#include <linux/module.h>	/* Needed by all modules */
#include <linux/kernel.h>	/* Needed for KERN_DEBUG */
#include <linux/init.h>		/* Needed for the macros */
#include <linux/jiffies.h>	/* Needed for the jiffies */
#include <linux/delay.h>	/* Needed for the delay */

static unsigned int delay_cnt = 10;

module_param(delay_cnt, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(delay_cnt, "An unsigned integer");

#define DRIVER_AUTHOR "Sachin Desai <sachinpdesai@hotmail.com>"
#define DRIVER_DESC   "Linux kernel module(lkm) test"

int time_profile(void) 
{
    int i;

    cycles_t start_cycle, end_cycle;
    unsigned long total_cycles = 0;

    unsigned long start_jiffies, end_jiffies;
    unsigned long total_jiffies = 0;

    start_cycle = get_cycles();
    start_jiffies = jiffies;

    for (i = 0; i < delay_cnt; i++) {
        ndelay(i);
        udelay(i);
        mdelay(i);
    }

    end_cycle = get_cycles();
    end_jiffies = jiffies;

    total_cycles += end_cycle - start_cycle;
    total_jiffies += end_jiffies - start_jiffies;

    printk(KERN_DEBUG "Test cylces = %ld\n", total_cycles);
    printk(KERN_DEBUG "Test jiffies = %ld\n", total_jiffies);

    return (0);
}

/* 
 * Get rid of taint message by declaring code as GPL. 
 */
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);

